package com.gdwhomework.ThreadHomework;

/**
 * @author 关道伟
 * @version 1.0
 */
public class HomeWork02 {
    public static void main(String[] args) {

        A a = new A();
        Thread thread = new Thread(a);
        Thread thread1 = new Thread(a);

        thread.start();
        thread1.start();


    }
}

class A implements Runnable {
    private static int money = 10000;

    @Override
    public void run() {

        while (true) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            synchronized (this) {
                if (money <= 0) {
                    break;
                }
                money -= 1000;
                System.out.println(Thread.currentThread().getName()
                        + "成功取出1000元 余额为" + money);

            }

        }


    }
}
